package org.example.guide.controller;

import org.example.guide.domain.Guide;
import org.example.guide.domain.Itinerary;
import org.example.guide.domain.Person;
import org.example.guide.domain.Transaction;
import org.example.guide.persistence.TripTeamFeign;
import org.example.guide.service.transactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/")
@EnableFeignClients(basePackages = "org.example.guide.persistence")
public class transactionController {
    @Autowired
    transactionService transactionservice;
   @Autowired
    TripTeamFeign tripTeamFeign;

    @GetMapping("/selectAllUpgrade")
    public List<Transaction> selectAllUpgrade(){
        return transactionservice.selectAllUpgrade();
    }

    @GetMapping("/selectAllRegister")
    public List<Transaction> selectAllRegister(){
        return transactionservice.selectAllRegister();
    }

    @GetMapping("/selectAllReport")
    public List<Transaction> selectAllReport(){
        return transactionservice.selectAllReport();
    }

    @GetMapping("/selectAllApply")
    public List<Transaction> selectAllApply(){
        return transactionservice.selectAllApply();
    }

    @GetMapping("/passUpgrade")
    public void passUpgrade(int id,int GuideID,String Qualification){
        transactionservice.passUpgrade(id, GuideID, Qualification);
    }
    @GetMapping("/passRegister")
    public void passRegister(int id,int GuideID){
        transactionservice.passRegister(id, GuideID);
    }
    @GetMapping("/passReport")
    public void passReport(int id,int GuideID,int TeamID){
        Guide guide=transactionservice.passReport(id, GuideID, TeamID);
         Person person= new Person();
         person.setPersonid(String.valueOf(guide.getId()));
         person.setAge(String.valueOf(guide.getAge()));
         person.setPersonname(guide.getName());
         person.setTeamid(String.valueOf(guide.getTeamID()));
         person.setType("导游");
         tripTeamFeign.send1(person);
    }
    @GetMapping("/passItinerary")
    public void passItinerary(int id,String itineraryid,String pass){
        transactionservice.deleteByID(id);
        Itinerary itinerary=new Itinerary();
        itinerary.setItineraryid(itineraryid);
        itinerary.setPass(pass);
        tripTeamFeign.send2(itinerary);
    }
    @GetMapping("/getItinerary")
    public Itinerary getItinerary(String itineraryid) {
        Itinerary itinerary=new Itinerary();
        itinerary.setItineraryid(itineraryid);
       itinerary=tripTeamFeign.get(itinerary);
            System.out.println(itinerary.toString());
            return itinerary;
    }
    @GetMapping("/deleteTransactionByID")
    public void deleteTransactionByID(int id){
        transactionservice.deleteByID(id);
    }

}
